class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        vector<int> ret;
        if(nums.empty())
        {
            return vector<int>({-1,-1});
        }
        //left
        int left=0,right=nums.size()-1;
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(nums[mid]>=target)
            {
                right=mid;
            }
            else 
            {
                left=mid+1;
            }
        }
        if(nums[left]==target)
            ret.push_back(left);
        else{
            return vector<int>({-1,-1});
        }
        left=0;
        right=nums.size()-1;
        while(left<right)
        {
            int mid=left+(right-left+1)/2;
            if(nums[mid]<=target)
            {
                left=mid;
            }
            else 
            {
                right=mid-1;
            }
        }
        if(left<nums.size() && nums[left]==target)
        {
            ret.push_back(left);
        }
        if(ret.empty())
        {
            return vector<int>({-1,-1});
        }
        else if(ret.size()==1)
        {
            ret.push_back(-1);
        }
        return ret;
    }
};
